Ext.define('AmpleHarvest.objects.groups.window.view.cToolbar',
{
	extend				: 'Ext.toolbar.Toolbar',
	alias		: 'widget.ampleharvest-objects-groups-window-view-ctoolbar',
	requires			:
	[
			'Ext.button.Button'
	],
	initComponent		: function()
	{
		var obj_This = this;

		this.m_obj_Add = Ext.create("Ext.button.Button",
		{
			text		: 'Edit',
			iconCls		: "menu-group-add-icon",
			scope		: this,
			handler		: function()
			{
				var obj_group_view = this.up('form');
				var obj_edit_button = this.down('button');
				
				var arr_form_elements = obj_group_view.query('field');
				
				
				
				for (object in arr_form_elements)
				{
					if( arr_form_elements[object].readOnly)
					{
						arr_form_elements[object].setReadOnly(false);
					}
					else
					{
						arr_form_elements[object].setReadOnly(true);
						
					}
				}
				if( arr_form_elements[object].readOnly)
				{
					obj_group_view.getForm().submit(
									{
										url		: obj_config.C_STR_EXTERNAL_PATH+'/rest/group/group.php',
										waitMsg	: 'Submiting Your Group Request',
										method	: "put",
										params	: {
											id	: obj_group_view.m_str_groupId,
										},
										success	: this.submit_Success,
										failure	: this.submit_Fail,
										scope	: this
									});	
//					obj_edit_button.text = 'Edit';
				}
				else
				{
//					obj_edit_button.text = 'Submit';
				}
			}
		});
	
		
		this.callParent();
		
		this.add(this.m_obj_Add);
	},

	submit_Success	: function(str_Function, mix_Arg)
	{
//		this.ownerCt.close();
		// REFRESH FORM PANEL DRAW

		Ext.MessageBox.alert("Success", "Your Request has been sent.", close);
	},

	submit_Fail		: function(str_Function, mix_Arg)
	{
		Ext.MessageBox.alert("Error", mix_Arg.result.errors.msg, close);
	}
});